% Reads the *.res files from x3dg (note all the 6 components!)
%fid = fopen('E:\manoj\ocean\source\180x360\monthly\apr01.res','rb');
%fid = fopen('E:\manoj\ocean\x3dg\apr00.res','rb');
fid = fopen('c:\manoj\ocean\x3dg\tsu_results\tsu10.res','rb')
%Used a binary editor to fix the header size of res files - date 21 oct
%2005
TimeID = [1314000, 3945600, 6577200, 9208800, 11840400, 14472000, 17103600, 19735200, 22366800, 24998400, 27630000, 30261600, 32893200, 35524800, ...
        38156400, 40788000, 43419600, 46051200, 48682800, 51314400, 53946000, 56577600, 59209200, 61840800, 64472400, 67104000, 69735600, 72367200, ...
        74998800, 77630400, 80262000, 82893600, 85525200, 88156800, 90788400, 93420000, 96051600, 98683200, 101314800, 103946400, 106578000, 109209600, ...
        111841200, 114472800, 117104400, 119736000, 122367600, 124999200, 127630800, 130262400, 132894000, 135525600, 138157200, 140788800, 143420400, ...
        146052000, 148683600, 151315200, 153946800, 156578400, 159210000, 161841600, 164473200, 167104800, 169736400, 172368000, 174999600, 177631200, ...
        180262800, 182894400, 185526000, 188157600, 190789200, 193420800, 196052400, 198684000, 201315600, 203947200, 206578800, 209210400, 211842000, ...
        214473600, 217105200, 219736800, 222368400, 225000000, 227631600, 230263200, 232894800, 235526400, 238158000, 240789600, 243421200, 246052800, ...
        248684400, 251316000, 253947600, 256579200, 259210800, 261842400, 264474000, 267105600, 269737216, 272368800, 275000384, 277632000, 280263616, ...
        282895200, 285526784, 288158400, 290790016, 293421600, 296053184, 298684800, 301316416, 303948000, 306579584, 309211200, 311842816, 314474400, ...
        317105984, 319737600, 322369216, 325000800, 327632384, 330264000, 332895616, 335527200, 338158784, 340790400, 343422016, 346053600];

MyInPath = 'E:\manoj\ocean\cable_results\x3dg\';

Month = ['Jan';'feb';'MAR';'apr';'may';'jun';'JUL';'aUG';'sep';'Oct';'NoV';'deC'];
Month = lower(Month);
Year = ['92';'93';'94';'95';'96';'97';'98';'99';'00';'01';'02'];
ij=1;

for i = 1:11,
    for j = 1:12,
        fname = [Month(j,:) Year(i,:) '.res'];
        disp([MyInPath fname]);
fid = fopen([MyInPath fname],'rb');
fread(fid,518400,'uchar'); %Header includes the gird size, files used for computation etc
[Hpr(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi; %in nT
[Hpi(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi;
[Htr(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi;
[Hti(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi;
[Hrr(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi;
[Hri(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*400*pi;
[Epr(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06; %in mV/km
[Epi(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06;
[Etr(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06;
[Eti(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06;
[Err(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06;
[Eri(ij,:,:)] = reshape(fread(fid,360*180,'float32'),[180,360])*1.E+06;
fclose(fid);
ij = ij+1;
    end;
end;

save